
package common.packet;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * Represents all packets which don't have data, just a code. For example,
 * START_GAME, LOGOUT and STOP_GAME.
 *
 * @author xissburg
 */
public class PacketWithCode implements Packet
{
    private Code code;

    public PacketWithCode(Code code)
    {
        this.code = code;
    }

    public PacketWithCode(DataInputStream in) throws IOException
    {
        this.code = Packet.Code.valueOf(in.readUTF());
    }

    public PacketWithCode(PacketWithCode packet) {
        this(packet.getCode());
    }

    public void read(DataInputStream in) throws IOException
    {
        
    }

    public void write(DataOutputStream out) throws IOException
    {
        out.writeUTF(code.name());
    }

    public Code getCode() {
        return code;
    }

    public PacketWithCode copy() {
        return new PacketWithCode(this);
    }
}
